package com.example.web_project_xianyu.mappers;

import com.example.web_project_xianyu.entity.Chat;
import com.example.web_project_xianyu.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface chatMapper {


    @Insert("insert into chat_table(from_id, to_id, chat_text, time, product_id) values(#{fromId}, #{toId}, #{chatText}, #{time}, #{productId})")
    void add_chat(Chat chat);

    @Select("select * from chat_table where product_id = #{product_id} and ( to_id=#{from_id} or from_id=#{from_id})")
    List<Chat> get_all_chat_of_one(@Param("product_id")int product_id, @Param("from_id")int from_id);

    @Select("select * from chat_table where from_id=#{from_id}")
    List<Chat> get_my_chated_product(int from_id);

    @Select("select * from chat_table where product_id=#{product_id} and from_id != #{user_id}")
    List<Chat> get_chat_by_product_id(@Param("product_id")int product_id,@Param("user_id")int user_id);

    @Delete("delete from chat_table where product_id=#{product_id}")
    void delete_product(int product_id);
}
